<?php
class SubscriptionModel extends BaseModel
{
	//自动验证
	protected $_validate = array(
	array('email','email','邮箱格式错误！',self::VALUE_VALIDATE),
	array('email','','邮箱地址已经存在！',0,'unique',self::EXISTS_VALIDATE),
	);

	public function edit($uid, $isSub, $email){
		$data = $this->find($uid);
		$data['update_time'] = time();
		if($data){
			//执行修改
			$data['is_sub'] = $isSub;
			$data['email'] = $email;
			$data = $this->create($data);
			if($data){
				return $this->save($data);
			}
		}else{
			//执行添加
			$data = array();
			$data['uid'] = $uid;
			$data['is_sub'] = $isSub;
			$data['email'] = $email;
			$data = $this->create($data);
			if($data){
				return $this->add($data);
			}
		}
		return $this->getError();
	}
}